package gll.pub.onepeas.util;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class PageUtil {
    private static final String DATAS2 = "datas";
    private static final String PAGE_COUNT = "pageCount";
    private static final String TOTAL_COUNT = "totalCount";
    private static final String PAGE_NO = "pageNo";

    public static Map<String,Object> packPagedMap(int pageNo,
                                                  int pageSize,
                                                  int totalCount,
                                                  List<?> datas){

        Map<String,Object> retvalMap=new LinkedHashMap<String,Object>();
        retvalMap.put(PAGE_NO, pageNo);
        retvalMap.put(TOTAL_COUNT, totalCount);

        int pageCount=(int)Math.ceil((double)totalCount/pageSize);
        retvalMap.put(PAGE_COUNT, pageCount);
        retvalMap.put(DATAS2, datas);

        return retvalMap;
    }

    public static int figureStart(int pageNo,int pageSize) {
        return pageNo*pageSize;
    }

    public static int figureEnd(int pageNo,int pageSize) {
        return (pageNo+1)*pageSize;
    }
}